﻿using System;
using System.Windows.Forms;

namespace PMS.Win
{
    public partial class FormException : BaseForm
    {
        public static DialogResult Show(string message, Exception exception)
        {
            return new FormException(message, exception).ShowDialog();
        }

        bool isShowDetail = false;
        public bool IsShowDetail
        {
            get { return isShowDetail; }
            set
            {
                 isShowDetail = value;
                 ResizeForm();
            }
        }

        string message = string.Empty;
        Exception exception = null;
        private FormException(string message, Exception exception)
        {
            InitializeComponent();

            this.message = message;
            this.exception = exception;
        }

        protected override void OnShown(EventArgs e)
        {
             lblErrorSummary.Text =  message;
             txtErrorDetail.Text =  exception.ToString();
             IsShowDetail = false;

            base.OnShown(e);
        }

        private void ResizeForm()
        {
            int errorheight = txtErrorDetail.Height;
            txtErrorDetail.Visible = IsShowDetail;
            if (IsShowDetail)
            {
                Height = Height + 5;
            }
            else
            {
                Height = Height - errorheight - 5;
            }
        }

        private void btnDetail_Click(object sender, EventArgs e)
        {
            IsShowDetail = !IsShowDetail;
        }
    }
}
